/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Gao zhao xu
 * Date: 2023-12-18
 * Time: 上午 10:35
 */

import java.util.PriorityQueue;
import java.util.Scanner;

public class Test3 {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int N = input.nextInt();
        for (int i = 0; i < N; i++) {
            int n = input.nextInt();
            PriorityQueue<Integer> minHeap = new PriorityQueue<>();
            int rst = 0;
            int x = 0;
            int y = 0;
            for (int j = 0; j < n; j++) {
                x = input.nextInt();
                minHeap.offer(x);
            }
            while (minHeap.size() > 1) {
                x = minHeap.poll();
                y = minHeap.poll();
                rst += (x + y);
                minHeap.offer(x + y);
            }
            System.out.println(rst);
        }
    }
}
